package com.sam.jifenbao;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MyWalletActivity extends BaseActivity {

    private ListView myWalletListView;

    public static final String KEY_SHOP_LOGO = "KEY_SHOP_LOGO";
    public static final String KEY_SHOP_NAME = "KEY_SHOP_NAME";
    public static final String KEY_POINTS_NUM = "KEY_POINTS_NUM";
    public static final String KEY_REDEEM_CASES = "KEY_REDEEM_CASES";
    public static final String KEY_COUPON_NUM = "KEY_COUPON_NUM";
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_wallet);
        findView();
        initView();
    }

    @Override
    protected void findView() {
        myWalletListView = (ListView) findViewById(R.id.my_wallet_listview);
    }

    @Override
    protected void initView(){

        final List<Map<String,Object>> data = new ArrayList<>();
        int[] logos = {R.drawable.portrait_drawable,R.mipmap.shop_logo_2,R.mipmap.shop_logo_3};
        for(int i = 0; i <20; i++){
            Map<String, Object> map = new HashMap<>();
            map.put(KEY_SHOP_LOGO,logos[i % 3]);
            map.put(KEY_SHOP_NAME,"卡路里先生第"+i+"家分店");
            map.put(KEY_POINTS_NUM,(i+2000)+"");
            map.put(KEY_REDEEM_CASES,(i+3)+"");
            map.put(KEY_COUPON_NUM,(i+2)+"");
            data.add(map);
        }
        SimpleAdapter couponAdapter = new SimpleAdapter(this,data,R.layout.my_wallet_listview_item,
                new String[]{KEY_SHOP_LOGO,KEY_SHOP_NAME, KEY_POINTS_NUM, KEY_REDEEM_CASES, KEY_COUPON_NUM},
                new int[]{R.id.shop_logo,R.id.shop_name,R.id.points_count,R.id.redeem_cases,R.id.coupon_count});
        myWalletListView.setAdapter(couponAdapter);
        myWalletListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                showShortToast("第"+position+"条被点击");
            }
        });
    }
}
